// class A {
//     name:string;
//     age:number;
//     constructor(name:string,age:number){
//         this.name = name;
//         this.age = age;
//     }
// }

// class B {
//     age:number;
//     entity:A;
//     constructor(age:number){
//         this.age = age;
//         this.entity = new A('zs')
//     }
// }

// const b = new B(18)
// console.log(b)

/**
 * 设置IOC 容器 就是控制反转 减少耦合度
 */

class A{
    name:string;
    constructor(name:string){
        this.name = name;
    }
}


class B{
    age:number;
    constructor(age:number){
        this.age = age;
    }
}

class Container{
    modules:any;
    constructor(){
        this.modules = {};
    }

    provide(key:string,value:any){
        this.modules[key] = value;
    }

    get(key:string){
        return this.modules[key];
    }
}

const mo = new Container();
mo.provide('A',new A('zs'));
mo.provide('B',new B(18));

class C{
    a:A;
    b:B;
    constructor(container:Container){
        this.a = container.get('A');
        this.b = container.get('B');
    }
}

const c = new C(mo);
console.log(c)